#pragma once

#include "Definitions.h"
#include "Structures.h"
#include <string>

#define NUMBUFFERS 4

struct RenderInfo{
	ID3D11Buffer* buffers[NUMBUFFERS];
	ID3D11Buffer* indexBuffer;
	ID3D11InputLayout* inputLayout;
	D3D_PRIMITIVE_TOPOLOGY topology;
	ID3D11ShaderResourceView* srv;
	ID3D11ShaderResourceView* normalMapSRV;
	ID3D11ShaderResourceView* specularMapSRV;
	ID3D11SamplerState* samplerState;
	ID3D11VertexShader* vs;
	ID3D11PixelShader* ps;
	ID3D11Buffer* objectCB;
	OBJECT object;
	UINT strides[NUMBUFFERS];
	UINT offsets[NUMBUFFERS];
	UINT numVerts, numIndices;
	UINT numBuffers, numTextures;
};

enum BufferType {POS,NORM,UV,TAN,IND,CB};

class Renderable
{

	ID3D11Buffer*  bPositions;
	ID3D11Buffer*  bNormals;
	ID3D11Buffer*  bUVs;
	ID3D11Buffer*  bTangents;
	ID3D11Buffer*  bIndices;
	ID3D11Buffer*  bObjectCB;
	ID3D11SamplerState* samplerState;
	ID3D11InputLayout* inputLayout;
	D3D_PRIMITIVE_TOPOLOGY topology;
	ID3D11VertexShader* vs;
	ID3D11PixelShader* ps;
	OBJECT object;
	UINT strides[NUMBUFFERS];
	UINT offsets[NUMBUFFERS];
	UINT numVerts;
	UINT numIndices;
	UINT numBuffers;
	int baseTexture;
	int normalMap;
	std::string key,normalKey;

public:
	Renderable();
	Renderable(RenderInfo info);
	~Renderable();

	ID3D11VertexShader* GetVS()			{ return vs; }
	ID3D11PixelShader* GetPS()			{ return ps; }
	ID3D11InputLayout* GetInputLayout()	{ return inputLayout; }
	ID3D11Buffer* GetConstantBuffer()	{ return bObjectCB; }

	void SetInputLayout(ID3D11InputLayout* inputLayout) { this->inputLayout = inputLayout; }
	void SetTopology(D3D_PRIMITIVE_TOPOLOGY topology) { this->topology = topology; }
	void SetVS(ID3D11VertexShader* vs)					{ this->vs = vs; }
	void SetPS(ID3D11PixelShader* ps)					{ this->ps = ps; }
	void SetNumIndices(int num) {numIndices = num;}
	void SetNumVerts(int num) {numVerts = num;}

	void SetBuffer(ID3D11Buffer* buffer, BufferType type, UINT* strides = nullptr, UINT* offsets = nullptr);
	RenderInfo GetRenderInformation();

	void LoadTexture(wchar_t* fileName);
	void SetKey(std::string key){this->key = key;}
	void SetNormalKey(std::string key){normalKey = key;}
	std::string GetKey(){return key;}
	std::string GetNormalKey(){return normalKey;}

	void SetRenderData(RenderInfo& data);
	void SetTexture(int index,int texture);

	//To Be moved to a child class
	void InitializeObject();




};

